<template>
  <div>
    <ul>
      <li v-for="message in messages" :key="message.id">
<!--        <a href="xxx">{{message.title}}</a>-->
        <router-link :to="`/home/message/detail/${message.id}`">{{message.title}}</router-link><!--详情信息跳转 es6语法使用``进行占位符-->
        <button @click="pushShow(message.id)">push查看</button>
        <button @click="replaceShow(message.id)">replace查看</button>
      </li>
    </ul>
    <button @click="$router.back()">回退</button>
    <button @click="$router.go(-1)">回退</button>
    <button @click="$router.go(1)">前进</button>
    <hr>
    <router-view></router-view><!--详情信息展现-->
  </div>
</template>

<script>
  export default {
    data () {
      return {
        messages: [
         /* {id: 1, title: 'Message001'},
          {id: 3, title: 'Message003'},
          {id: 5, title: 'Message005'}*/
        ]
      }
    },

    mounted () {
      setTimeout(() => {// 模拟从后台异步加载
        const messages = [
          {id: 1, title: 'Message001'},
          {id: 2, title: 'Message003'},
          {id: 3, title: 'Message005'}
        ]
        this.messages = messages
      }, 1000)
    },

    methods: {
      pushShow (id) {
        this.$router.push(`/home/message/detail/${id}`) // 调用this.$router方法，使用的是stack数据结构，push一个路由
      },

      replaceShow(id) {
        this.$router.replace(`/home/message/detail/${id}`)
      }
    }
  }
</script>

<style>

</style>
